﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverRaport.MySilverRaporService;

namespace SilverRaport
{
    public partial class RaporListe : ChildWindow
    {
        MySilverRaporService.SilverRaporServiceClient MyService = new MySilverRaporService.SilverRaporServiceClient();
        public RaporListe()
        {
            InitializeComponent();
            GridDoldur();
            MyService.RaporSilCompleted += (a, s) =>
            {
                if (s.Result)
                {
                    MessageBox.Show("Kayıt Silinmiştir.!");
                    GridDoldur();
                }
                else
                    MessageBox.Show("Bir Hata Oluştu..!!", "Hata", MessageBoxButton.OK);
            };
        }

        private void GridDoldur()
        {
            MyService.RaporListeleAsync(SqlPage.KullaniciID);
            MyService.RaporListeleCompleted += new EventHandler<MySilverRaporService.RaporListeleCompletedEventArgs>(MyService_RaporListeleCompleted);
        }

        void MyService_RaporListeleCompleted(object sender, MySilverRaporService.RaporListeleCompletedEventArgs e)
        {
            GridRapor.ItemsSource = e.Result;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            Degistir();
            this.DialogResult = true;
        }

        private void Degistir()
        {
            RaporListele.RaporID = ((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).RaporID;
            RaporListele.RaporSQL = ((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).RaporSQL;
            RaporListele.RaporIsim = ((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).RaporIsim;
            RaporListele.RaporInterval = ((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).RaporInterval;

            RaporListele.RaporTipi = ((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).RaporTipi;
            RaporListele.GrafikTipi = ((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).GrafikTipi;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void btnSil_Click(object sender, RoutedEventArgs e)
        {
            MyService.RaporSilAsync(((SilverRaport.MySilverRaporService.RaporListe)GridRapor.SelectedItem).RaporID, SqlPage.KullaniciID);

            GridDoldur();
        }
    }
}

